﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title></title>
    <link href="../Layui/css/layui.css" rel="stylesheet" />
    <style>
        .teacherCourse {
            border-radius: 5px;
            padding: 5px;
            margin: 5px;         
        }
        .teacherCourseTd {
            padding: 0px !important;
            width: 10rem;
        }
        .teacherCourseTd1 {
            padding: 0px !important;
            width: 10rem;
            height: 60px;
        }
       

        body {
            background-color: #fff;
        }
        .btnEdit {
            width: 0.8rem;
            float: right;
            margin-right: 5px;            
            cursor:pointer;
        }
        .btnAdd {
            width: 0.8rem;
            float: right;
            margin-right: 15px;
            cursor: pointer;
        }
        .layui-table th {
            text-align:center;
        }
    </style>
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-tab layui-tab-brief" lay-filter="tab">
            <ul class="layui-tab-title">
                <li class="layui-this">日课表</li>
                <li>周课表</li>
                <li>月课表</li>
            </ul>
            <div style="float:right;margin-top:-40px;margin-right:10px;width:100px;">
                <select id="range" class="layui-input-block  layui-form" lay-filter="range"  >
                    <option value="0">全部排课</option>
                    <option value="1">仅自己</option>
                </select>
            </div>
            <div class="layui-tab-content" style="height: 100px;">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form">
                        <div style="float:right">
                            <button class="layui-btn layui-btn-normal" style="width:100px;">打印课表</button>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" name="date" id="date" lay-verify="date" placeholder="请选择日期" autocomplete="off" class="layui-input" value="@DateTime.Now.ToString("yyyy-MM-dd")">
                            </div>

                        </div>
                        <div id="divD">
                            <table class="layui-table">
                                <thead>
                                    <tr>
                                        <th>课程表</th>
                                        <th v-for="item in Data.header">{{item.name}}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr v-for="item1 in Data.time">
                                        <td style="width:3rem">{{item1.starttime}}-{{item1.endtime}}</td>
                                        <template v-for="item2 in Data.header">
                                            <td class="teacherCourseTd">
                                                <template v-for="item3 in Data.teacherCourse" v-if="item1.id==item3.timeid&&item2.id==item3.classroomid">
                                                    <div v-bind:style="{background: item3.color}" class="teacherCourse">
                                                        <span style="color:white">{{item3.coursename}}-{{item3.teachername}} {{item3.twoteachername}}</span>                                                       
                                                        <img src="../images/icon_edit.png" class="btnEdit" @Html.Raw("@click")="openEdit(item3.id,item3.keycode)" v-if="isEdit" />
                                                    </div>
                                                </template>
                                                <img src="../images/icon_add.png" class="btnAdd" @Html.Raw("@click")="openAdd(item1.id,item2.id)" v-if="isEdit&&countCourse(item1.id,item2.id)" />
                                            </td>
                                        </template>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="layui-tab-item">
                    <div class="layui-form">
                        <div style="float:right">
                            <button class="layui-btn layui-btn-normal">打印课表</button>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <div class="layui-input" style="border: none;line-height: 38px;">
                                    <a href="javascript:lastWeek()"><上一周</a>
                                    <a href="javascript:nextWeek()">下一周></a>
                                </div>
                            </div>
                        </div>
                        <div id="divW">
                            <table class="layui-table">
                                <thead>
                                    <tr>
                                        <th>课程表</th>
                                        <th v-for="item in Data.header">{{item.name}}<br />{{item.date}}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr v-for="item1 in Data.time">
                                        <td style="width:3rem">{{item1.starttime}}-{{item1.endtime}}</td>
                                        <template v-for="item2 in Data.header">
                                            <td class="teacherCourseTd1">
                                                <template v-for="item3 in Data.teacherCourse" v-if="item1.id==item3.timeid&&item2.id==item3.weekid">
                                                    <div v-bind:style="{background: item3.color}" class="teacherCourse">
                                                        <span style="color:white">{{item3.coursename}}-{{item3.teachername}} {{item3.twoteachername}}</span>                                                        
                                                        <img src="../images/icon_edit.png" class="btnEdit" @Html.Raw("@click")="openEdit(item3.id,item3.keycode)" v-if="item3.teachdate>=now" />
                                                    </div>
                                                </template>                                                
                                            </td>
                                        </template>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>

                <div class="layui-tab-item">
                    <div class="layui-form">
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="dateYM" value='@DateTime.Now.ToString("yyyy-MM")'>
                            </div>
                        </div>
                        <div id="divM" style="margin-top:1rem">
                            <table class="layui-table">
                                <thead>
                                    <tr>
                                        <th v-for="item in Data.header">{{item.name}}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr v-for="i in 6">
                                        <template v-for="item2 in Data.header">
                                            <td class="teacherCourseTd1" valign="top">
                                                <div style="text-align:right;padding-top:2px;padding-right:5px;" v-if="calDay(i,item2.id)>0">{{calDay(i,item2.id)}}</div>
                                                <template v-for="item3 in Data.teacherCourse" v-if="calDay(i,item2.id)==item3.day">
                                                    <div v-bind:style="{background: item3.color}" class="teacherCourse">
                                                        <span style="color:white">{{item3.coursename}}-{{item3.teachername}} {{item3.twoteachername}}</span>                                                        
                                                    </div>
                                                </template>
                                            </td>
                                        </template>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
</form>
        <script type="text/javascript" src="../Htc/vue.js"></script>
        <script type="text/javascript" src="../Htc/jquery-1.11.2.min.js"></script>
        <script type="text/javascript" src="../Layui/layui.js"></script>
        <script>

            var tabIndex = 0;
            layui.use(['form', 'laydate', 'element'], function () {
                var laydate = layui.laydate;
                var form = layui.form;
                var element = layui.element;
                //执行一个laydate实例
                laydate.render({
                    elem: '#date' //指定元素
                    ,done: function (value, date, endDate) {
                        getDayData();
                    }
                });

                //tab切换
                element.on('tab(tab)', function (data) {
                    tabIndex = data.index;
                    if (tabIndex == 0)
                        getDayData();
                    else if (tabIndex == 1)
                        getWeekData();
                    else
                        getMonthData();
                });

                form.on('select(range)', function (data) {
                    if (tabIndex == 0)
                        getDayData();
                    else if (tabIndex == 1)
                        getWeekData();
                    else
                        getMonthData();
                });

                //年月选择器
                laydate.render({
                    elem: '#dateYM'
                    ,type: 'month'
                    ,done: function (value, date, endDate) {
                        vmM.date = value + '-01';
                        getMonthData();
                    }
                });
            });

            var vmD = new Vue({
                el: '#divD',
                data: {
                    Data: {},
                    isEdit:false
                },
                methods: {
                    openEdit: function (id,keyCode) {
                        openCourse(id,keyCode, 0, 0);
                    },
                    openAdd: function (timeId, classId) {
                        openCourse(-1,'', timeId, classId);
                    },
                    countCourse: function (timeid, classroomid) {//判断是否有课
                        for (var i = 0; i < this.Data.teacherCourse.length; i++) {
                            var dr = this.Data.teacherCourse[i];
                            if (dr.timeid == timeid && dr.classroomid == classroomid)
                                return false;
                        }
                        return true;
                    }
                }
            });
            var vmW = new Vue({
                el: '#divW',
                data: {
                    Data: {},
                    now: '@DateTime.Now.ToString("yyyy-MM-dd")',//选择日期<当前日期不能修改增加
                    date: '@ViewBag.weekFirst'//周一日期
                },
                methods: {
                    openEdit: function (id,keyCode) {
                        openCourse(id,keyCode, 0, 0);
                    },

                }
            });
            var vmM = new Vue({
                el: '#divM',
                data: {
                    Data: {},
                    date: '@DateTime.Now.ToString("yyyy-MM-01")'//月首日
                },
                methods: {
                    calDay: function (i, j) {
                        var day = (i - 1) * 7 + j * 1 - this.Data.startWeekId + 1;
                        if (day < 1) day = 0;
                        if (day > this.Data.dayCount) day = 0;
                        return day;
                    }
                }
            });


            //获取按天数据
            function getDayData() {
                vmD.isEdit = $("#date").val() >='@DateTime.Now.ToString("yyyy-MM-dd")',//选择日期<当前日期不能修改增加;
                $.ajax({
                    type: 'POST',
                    url: '../Schedule/TeacherClass/DayData',
                    data: {
                        date: $("#date").val(),
                        range: $("#range").val()
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.code == "0000") {
                            vmD.Data = data.data;
                        }
                        else
                            layui.layer.msg(data.message);
                    }
                });
            }
            //获取按周数据
            function getWeekData() {
                vmW.isEdit = $("#date").val() >= '@DateTime.Now.ToString("yyyy-MM-dd")';
                $.ajax({
                    type: 'POST',
                    url: '../Schedule/TeacherClass/WeekData',
                    data: {
                        date:vmW.date,
                        range: $("#range").val()
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.code == "0000") {
                            vmW.Data = data.data;
                        }
                        else
                            layui.layer.msg(data.message);
                    }
                });
            }
            //获取按月数据
            function getMonthData() {
                $.ajax({
                    type: 'POST',
                    url: '../Schedule/TeacherClass/MonthData',
                    data: {
                        date: vmM.date,
                        range: $("#range").val()
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.code == "0000") {
                            vmM.Data = data.data;
                        }
                        else
                            layui.layer.msg(data.message);
                    }
                });
            }
            //上一周
            function lastWeek() {
                var date = new Date(vmW.date);
                date.setDate(date.getDate() - 7);
                vmW.date = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
                getWeekData();
            }
            //下一周
            function nextWeek(){
                var date = new Date(vmW.date);
                date.setDate(date.getDate() + 7);
                vmW.date = date.getFullYear() + '-' + (date.getMonth()+1) + '-' + date.getDate();
                getWeekData();
            }
            //打开编辑
            function openCourse(id,keyCode,timeId, roomId) {
                var title = '修改排课';
                if (id == -1) title = "增加排课";
                var index = layui.layer.open({
                    type: 2,//0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）                    
                    content: '../Schedule/Course?id=' + id + '&keyCode=' + keyCode + '&timeId=' + timeId + '&roomId=' + roomId,
                    title: title,
                    maxmin: true
                });
                layui.layer.full(index);
            }
            //初始加载获取天数
            getDayData();

            function HideModal(id) {
                layui.layer.closeAll();
            }
            //刷新数据
            function Reload() {
                if (tabIndex == 0)
                    getDayData();
                else if (tabIndex == 1)
                    getWeekData();
                else
                    getMonthData();
            }
        </script>
</body>
</html>
